import { Injectable } from '@angular/core';
import { NzDrawerService } from 'ng-zorro-antd/drawer';
import { Observable } from 'rxjs';
import { TenantDto } from '../proxy';
import { RefFeatureComponent } from './ref-feature.component';

@Injectable({
  providedIn: 'root',
})
export class RefFeatureService {
  private defaultTitle: 'HOST功能' | '租户功能' = '租户功能';
  private defaultWidth: number = 800;
  constructor(protected drawerService: NzDrawerService) {}
  show(
    model: { providerName: string; keyModel?: TenantDto },
    options?: { title?: string; width?: number }
  ): Observable<any> {
    var nzTitle = !options?.title ? this.defaultTitle : options.title;
    var nzWidth = !options?.width ? this.defaultWidth : options.width;
    var providerKey = !!model.keyModel ? model.keyModel.id : '';
    var providerName = 'T';
    const drawerRef = this.drawerService.create<RefFeatureComponent, { value: string }, string>({
      nzTitle: nzTitle,
      nzWidth: nzWidth,
      nzContent: RefFeatureComponent,
      nzContentParams: {
        providerName: model.providerName,
        providerKey: providerKey,
      },
    });
    return drawerRef.afterClose;
  }
}
